package com.qingke.memo.command.system;

import com.qingke.memo.command.SystemCommand;
import com.qingke.memo.pojo.Memo;
import com.qingke.memo.pojo.MemoCustomTag;
import com.qingke.memo.unit.MConsole;

public class DeleteMemo extends SystemCommand {

	@Override
	public void execute() {
		int id=MConsole.getInt("input memo id:");
		if(!dao.isMemoExistById(id)){
			MConsole.println("the memo is not exist.");
			return ;
		}
		
		
		Memo memo=dao.selectMemoById(id);
		
		MemoCustomTag memoCustomTag=new MemoCustomTag();
		memoCustomTag.setMemoId(memo.getId());
		if(dao.isMemoCustomTagExistByMemo(memoCustomTag)){
			MConsole.println("please delete memo custom tag first");
			return ;
		}
		
		boolean isSuccess=dao.deleteMemo(memo);
		if(isSuccess)
			MConsole.println("delete memo success.");
		else
			MConsole.println("delete memo failed.");
	}

}
